<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <script>
    function quick(arr) {
      if (!arr.length || arr.length < 2) return arr;
      const left = [];
      const equal = [];
      const right = [];

      const middleIndex = Math.floor(arr.length / 2);
      const middle = arr[middleIndex];

      for (let i = 0; i < arr.length; i++) {
    
        const element = arr[i];
        if (element < middle) {
          left.push(element);
        } else if (element > middle) {
          right.push(element);
        } else {
          equal.push(element);
        }
      }

      return [...quick(left), ...equal, ...quick(right)];
    }
  </script>
  <body></body>
</html>
